package com.yonyou.pmclouds.projecttype.process;

import com.yonyou.pmclouds.basecom.bp.processor.SingleProcessor;
import com.yonyou.pmclouds.basecom.exception.BusinessException;
import com.yonyou.pmclouds.basecom.ref.itf.RefCodeConst;
import com.yonyou.pmclouds.basecom.ref.itf.ReferenceChecker;
import com.yonyou.pmclouds.projecttype.entity.ProjectTypeVO;
import com.yonyou.pmclouds.projecttype.mapper.ProjectTypeMapper;

public class ProjectTypeDeleteCheckProcessor implements SingleProcessor<ProjectTypeVO> {
    private ProjectTypeMapper mapper;
    private ReferenceChecker referenceChecker;
    public ProjectTypeDeleteCheckProcessor(ProjectTypeMapper mapper,ReferenceChecker referenceChecker){
        this.mapper=mapper;
        this.referenceChecker=referenceChecker;
    }
    @Override
    public void process(ProjectTypeVO vo, ProjectTypeVO orig) throws BusinessException {
        int count = mapper.chirdrenCount(vo.getPkProjectType(), vo.getPkTenant());
        if (count!=0){
            throw new BusinessException("存在下级，不允许删除");
        }else{
            if (referenceChecker.checkReferenced(RefCodeConst.PROJECTTYPE, new String[]{vo.getPkProjectType()})) {
                throw new BusinessException("该项目档案类型已被引用，不允许删除");
            }
        }
    }
}
